<%-- 
    Document   : productos
    Created on : 19-mar-2009, 2:31:41
    Author     : Administrador
--%>

<%@page session='true'%>
<%@ include file="conexion.jsp" %> 

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Productos</title>
        <link rel="STYLESHEET" type="text/css" href="estilos.css">
    </head>
    <body>
        <center>
        <%  
            String nick = session.getAttribute("nick").toString();
            int codigo=0;
            String tipo="";
            Statement instruccion = null;   
            ResultSet rs = null;
            Connection con = getConexion();
            try{
                instruccion = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
                //extraemos el codigo de proveedor
                rs =  instruccion.executeQuery("SELECT usu_tipo FROM usuario where usu_nick = '"+nick+"'");
                while(rs.next()){   
                    tipo = rs.getString(1);
                }
                if(tipo.equals("comprador"))
                {
                    rs = instruccion.executeQuery("SELECT c.comp_codigo FROM comprador c, usuario u where u.usu_nick = '"+nick+"' and u.usu_codigo = c.usu_codigo");
                    while(rs.next()){   
                        codigo = rs.getInt(1);
                    }
                }
                else
                {
                    rs = instruccion.executeQuery("SELECT p.prov_codigo FROM proveedor p, usuario u where u.usu_nick = '"+nick+"' and u.usu_codigo = p.usu_codigo");
                    while(rs.next()){   
                        codigo = rs.getInt(1);
                    }
                }
            }   
            catch(Exception e){out.println(e);} 
        %>
<% 
    if(tipo.equals("comprador"))
    {
%>

        <h2>Productos</h2>
        <h3>Laboratorios:</h3>
        <br>
        <%
            instruccion = null;   
            rs = null;
            con = getConexion();
            try{
                instruccion = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
                //extraemos los laboratorios
                rs =  instruccion.executeQuery("select * from laboratorio order by lab_nombre");
                while(rs.next()){   
                    out.println("<a href='mostrarProductosLab.jsp?lab_codigo="+rs.getInt(1)+"'>"+rs.getString(2)+"</a><br><br>");
                }
            }   
            catch(Exception e){out.println(e);} 
        %>
       
        <hr>
            
<% 
    }
    else
    {
%>        
    <h2>Mis Productos</h2>
    <table>
        <tr>
            <th>Nombre</th>
            <th>Laboratorio</th>
            <th>Registro Sanitario</th>
            <th>Clasificación ATC</th>
            <th>Costo unitario</th>
            <th> </th>
            <th> </th>
            <th> </th>
        </tr>
<%
        instruccion = null;   
        rs = null;
        con = getConexion();
        try{
            instruccion = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
            //extraemos los productos del proveedor
            rs =  instruccion.executeQuery("select * from productos where prov_codigo='"+codigo+"' order by pro_nombre_comercial");
            ResultSet rs2 = null;
            Statement instruccion2 = null;
            Connection con2 = getConexion();
            instruccion2 = con2.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);

            while(rs.next()){ 
                out.println("<tr>");
                out.println("<td>"+rs.getString(2)+"</td>");
                rs2 = instruccion2.executeQuery("select lab_nombre from laboratorio where lab_codigo="+rs.getInt(5));
                while(rs2.next()){   
                    out.println("<td>"+rs2.getString(1)+"</td>");
                }
                out.println("<td>"+rs.getString(3)+"</td>");
                out.println("<td>"+rs.getString(6)+"</td>");
                out.println("<td>"+rs.getFloat(8)+"</td>");
                out.println("<td><a href='#'><font size='-1'>ver presentaciones</font></a></td>");
                out.println("<td><a href='#'><font size='-1'>Modificar</font></a></td>");
                out.println("<td><a href='#'><font size='-1'>Eliminar</font></a></td>");
                out.println("</tr>");
            }
        }   
        catch(Exception e){out.println(e);} 
%>
    </table>
    <hr>
    
<% 
    }
%>  
    <br><br><a href="javascript:history.back()">Regresar</a>
    </center>
    </body>
</html>
